import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
// 引入全局axios
import axios from "axios";
import VueAxios from "vue-axios";
Vue.use(VueAxios, axios);
axios.defaults.baseURL = "http://120.77.159.56:3000/data/";
// axios.defaults.baseURL = "http://127.0.0.1:3000/data/";
// 全局引入swiper
import VAS from "vue-awesome-swiper";
Vue.use(VAS);
import "swiper/css/swiper.css";
// 引ElementUI
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
Vue.use(ElementUI);

// 引入Echarts
import echarts from "echarts";
Vue.prototype.$echarts = echarts;

Vue.config.productionTip = false;

router.beforeEach((to, from, next) => {
  if (to.meta.rootlogin) {
    // 需要权限
    //判断当前是否拥有权限
    if (localStorage.getItem("token")) {
      next();
    } else {
      // 无权，跳转登录
      next({
        path: "/rootlogin",
        query: {
          redirect: from.fullPath,
        },
      });
    }
  } else {
    // 不需要权限，直接访问
    next();
  }
});

new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount("#app");
